
import requests
from attr import dataclass


@dataclass
class HttpRequest:
	'''
		请求的服务器，接口地址，请求方法，数据类型，url参数，body参数
	'''
	host:str = None
	path:str = None
	method:str = None
	type:str = 'form'
	header:dict = None
	urlParams:dict = None
	bodyData:dict = None

	def send(self):
		'''
			暂时仅支持form表单格式和json数据格式
		'''
		response = None
		if self.type == 'json':
			response = requests.request(url=self.host+self.path,headers=self.header,method=self.method,json=self.bodyData,params=self.urlParams)
		elif self.type == 'form':
			response = requests.request(url=self.host+self.path,headers=self.header,method=self.method,data=self.bodyData,params=self.urlParams)
		else:
			raise Exception("请求数据格式未定义或不正确")
		return response

